package com.greensam.api.controller.user;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.greensam.api.controller.base.BaseController;
import com.greensam.domain.dto.request.RegisterRequest;
import com.greensam.common.mq.CommonResult;
import com.greensam.domain.dto.request.LoginRequest;
import com.greensam.server.service.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Author: Machengrui
 * @Date: 2024/9/23 16:23
 */
@Tag(name = "用户管理", description = "先简单实现，后续再优化")
@RestController
@RequestMapping("/base-user")
@RequiredArgsConstructor
public class UserController extends BaseController {

    @Resource
    private UserService userService;

    @ApiOperationSupport(order = 1)
    @Operation(summary = "用户登录")
    @PostMapping("/login")
    public CommonResult<?> login(@RequestBody LoginRequest request) {
        userService.login(request);
        return CommonResult.success();
    }

    @ApiOperationSupport(order = 2)
    @Operation(summary = "用户注册")
    @PostMapping("/register")
    public CommonResult<?> register(@RequestBody RegisterRequest request) {
        userService.register(request);
        return CommonResult.success();
    }

    @ApiOperationSupport(order = 3)
    @Operation(summary = "注销")
    @PostMapping("/logout")
    public CommonResult<?> logout() {
        return CommonResult.success();
    }
}

